package com.xxin.resp;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 小欣
 * @version 1.0
 * @since 1.8
 */
@Data
@Builder
@AllArgsConstructor
public class Result<T> {
  private Integer code;
  private String message;
  private T data;
  public Result(){}
  
  //成功
  public static final Integer OK = 200;
  //失败
  public static final Integer ERROR = 0;
  
  
  public static <T> Result<T> success(T data){
    return Result.<T>builder()
                   .code(OK)
                   .data(data)
                   .build();
  }
  
  public static <T> Result<T> success(){
    return Result.<T>builder()
                   .code(OK)
                   .build();
  }
  public static <T> Result<T> error(){
    return Result.<T>builder()
                   .code(ERROR)
                   .build();
  }
  public static <T> Result<T> error(String message){
    return Result.<T>builder()
                   .code(ERROR)
                   .message(message)
                   .build();
  }
 
}
